//
//  HomeCollectionViewCell.m
//  ATMCash
//
//  Created by zhengchengfeng on 2024/9/21.
//

#import "HomeCollectionViewCell.h"

@implementation HomeCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        self.backV = [[UIView alloc] init];
        [self addSubview:self.backV];
        self.backV.backgroundColor = [UIColor whiteColor];
        [self.backV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(15);
            make.right.equalTo(self.mas_right).offset(-15);
            make.top.equalTo(self.mas_top).offset(12);
            make.bottom.equalTo(self.mas_bottom).offset(0);
        }];
        self.backV.layer.cornerRadius = 12;
        self.backV.layer.masksToBounds = YES;

        self.logoV = [[UIImageView alloc] init];
        [self.backV addSubview:self.logoV];
        [self.logoV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.backV.mas_left).offset(15);
            make.top.equalTo(self.backV.mas_top).offset(15);
            make.width.with.height.equalTo(@24);
        }];
        self.logoV.image = [UIImage imageNamed:@"icon_logo"];

        self.nameLab = [Utility createLabel:[UIFont fontWithName:kFuturaBT size:14] color:[UIColor colorWithHexString:@"#022D06"]];
        [self.backV addSubview:self.nameLab];
        [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.logoV.mas_right).offset(5);
            make.height.equalTo(@20);
            make.right.equalTo(self.backV.mas_right).offset(-160);
            make.centerY.equalTo(self.logoV.mas_centerY);
        }];

        self.rateLab = [Utility createLabel:[UIFont fontWithName:kFutura size:12] color:[UIColor colorWithHexString:@"#00BA60"]];
        [self.backV addSubview:self.rateLab];
        [self.rateLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.backV.mas_right).offset(-15);
            make.width.equalTo(@140);
            make.height.equalTo(@30);
            make.centerY.equalTo(self.logoV.mas_centerY);
        }];
        self.rateLab.backgroundColor = [UIColor colorWithHexString:@"#F1F3F2"];
        self.rateLab.layer.cornerRadius = 15;
        self.rateLab.layer.masksToBounds = YES;
        self.rateLab.textAlignment = 1;

        self.lineV = [[UIView alloc] init];
        self.lineV.backgroundColor = kLineColor;
        [self.backV addSubview:self.lineV];
        [self.lineV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.logoV.mas_left);
            make.right.equalTo(self.rateLab.mas_right);
            make.top.equalTo(self.logoV.mas_bottom).offset(15);
            make.height.equalTo(@1);
        }];

        self.priceLab = [Utility createLabel:[UIFont fontWithName:kFuturaBold size:20] color:[UIColor colorWithHexString:@"#022D06"]];
        [self.backV addSubview:self.priceLab];
        [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.logoV.mas_left);
            make.top.equalTo(self.lineV.mas_bottom);
            make.right.equalTo(self.backV.mas_right).offset(-140);
            make.bottom.equalTo(self.backV.mas_bottom);
        }];
        self.priceLab.numberOfLines = 2;


        UIImage *imgB = [UIImage imageNamed:@"icon_btnBv1"];
        self.takeBtn = [[UIButton alloc] init];
        [self.takeBtn setBackgroundImage:imgB forState:UIControlStateNormal];
        self.takeBtn.titleLabel.font = [UIFont fontWithName:kFuturaMedium size:13];
        [self.takeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.backV addSubview:self.takeBtn];
        [self.takeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@90);
            make.centerY.equalTo(self.priceLab.mas_centerY);
            make.right.equalTo(self.backV.mas_right).offset(-15);
            make.height.equalTo(@34);
        }];
        [self.takeBtn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
        self.takeBtn.hidden = YES;
        
    }
    return self;
}

- (void)setListM:(HomeProductListModel *)listM{
    _listM = listM;

    [self.logoV sd_setImageWithURL:[NSURL URLWithString:esString(listM.generations)] placeholderImage:[UIImage imageNamed:@"icon_logo"]];
    self.nameLab.text = esString(listM.harness);
    self.rateLab.text = [NSString stringWithFormat:@"%@ | %@",esString(listM.purse),esString(listM.suppressing)];
    [self.takeBtn setTitle:esString(listM.fierce) forState:UIControlStateNormal];
    self.priceLab.text = [NSString stringWithFormat:@"%@\n%@",esString(listM.satisfy),esString(listM.fighter)];
    [self.priceLab addAttributesArray:@[@{NSFontAttributeName:[UIFont fontWithName:kFutura size:13]},@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#638473"]}] forStringArray:@[esString(listM.fighter),esString(listM.fighter)]];
    
    
    if (PMStringIsEmpty(listM.fierce)) {
        self.takeBtn.hidden = YES;
    } else {
        self.takeBtn.hidden = NO;
    }
    
    self.rateLab.adjustsFontSizeToFitWidth = YES;
    self.nameLab.adjustsFontSizeToFitWidth = YES;
    
    
}

- (void)clickBtn{
    if (_clickBtnBlock) {
        _clickBtnBlock(_listM);
    }
}


@end
